package com.fancy.display
{
	import com.fancy.framework.Macro;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.display.Stage;

	public class GameStage
	{
		/** 游戏状态:预加载主程序，相关资源 */
		public static const STAT_PRE_LOAD:String = "stat_pre_load";
		/** 游戏状态:登陆界面，连接服务器 */
		public static const STAT_LOGIN:String = "stat_login";
		/** 游戏状态:地图加载 */
		public static const STAT_MAP_LOAD:String = "stat_map_load";
		/** 游戏状态:正常游戏状态 */
		public static const STAT_NORMAL:String = "stat_normal";
		/** 游戏状态:提示性锁定(除了提示不可以点击其它地方) */
		public static const STAT_LOCK_ALERT:String = "stat_lock_alert";
		
		/** 游戏状态 */
		private static var _curState:String = Macro.STR_NULL;
		public static function get curState():String { return _curState; }
		
		/** 提示层 */
		private static var _AlertLayer:Sprite = new Sprite();
		public static function get AlertLayer():Sprite { return _AlertLayer; }
		/** 预加载层 */
		private static var _PreLoadLayer:Sprite = new Sprite();
		public static function get PreLoadLayer():Sprite { return _PreLoadLayer; }
		/** 加载地图层 */
		private static var _MapLoadLayer:Sprite = new Sprite();
		public static function get MapLoadLayer():Sprite { return _MapLoadLayer; }
		/** UI层 */
		private static var _UILayer:Sprite = new Sprite();
		public static function get UILayer():Sprite { return _UILayer; }
		/** 活动层(人物、技能等) */
		private static var _ActiveLayer:Sprite = new Sprite();
		public static function get ActiveLayer():Sprite { return _ActiveLayer; }
		/** 地图层 */
		private static var _MapLayer:Sprite = new Sprite();
		public static function get MapLayer():Sprite { return _MapLayer; }
		
		public function GameStage()
		{
		}
		
		public static function init(stage:Stage):void
		{
			stage.addChild(_MapLayer);
			stage.addChild(_ActiveLayer);
			stage.addChild(_UILayer);
			stage.addChild(_MapLoadLayer);
			stage.addChild(_PreLoadLayer);
			stage.addChild(_AlertLayer);
			//
			switchState(STAT_PRE_LOAD);
		}
		
		public static function switchState(state:String):void
		{
			if(_curState != state)
			{
				_curState = state;
				updateState();
			}
		}
		
		public static function updateState():void
		{
			switch(_curState)
			{
			case STAT_PRE_LOAD:
				unlockLayer(_AlertLayer);
				unlockLayer(_PreLoadLayer);
				lockLayer(_MapLoadLayer);
				lockLayer(_UILayer);
				lockLayer(_ActiveLayer);
				lockLayer(_MapLayer);
				_AlertLayer.visible = true;
				_PreLoadLayer.visible = true;
				_MapLoadLayer.visible = false;
				_UILayer.visible = false;
				_ActiveLayer.visible = false;
				_MapLayer.visible = false;
				break;
			case STAT_LOGIN:
				unlockLayer(_AlertLayer);
				lockLayer(_PreLoadLayer);
				lockLayer(_MapLoadLayer);
				unlockLayer(_UILayer);
				lockLayer(_ActiveLayer);
				lockLayer(_MapLayer);
				_AlertLayer.visible = true;
				_PreLoadLayer.visible = false;
				_MapLoadLayer.visible = false;
				_UILayer.visible = true;
				_ActiveLayer.visible = false;
				_MapLayer.visible = false;
				break;
			case STAT_MAP_LOAD:
				unlockLayer(_AlertLayer);
				lockLayer(_PreLoadLayer);
				unlockLayer(_MapLoadLayer);
				lockLayer(_UILayer);
				lockLayer(_ActiveLayer);
				lockLayer(_MapLayer);
				_AlertLayer.visible = true;
				_PreLoadLayer.visible = false;
				_MapLoadLayer.visible = true;
				_UILayer.visible = false;
				_ActiveLayer.visible = false;
				_MapLayer.visible = false;
				break;
			case STAT_NORMAL:
				unlockLayer(_AlertLayer);
				lockLayer(_PreLoadLayer);
				lockLayer(_MapLoadLayer);
				unlockLayer(_UILayer);
				unlockLayer(_ActiveLayer);
				unlockLayer(_MapLayer);
				_AlertLayer.visible = true;
				_PreLoadLayer.visible = false;
				_MapLoadLayer.visible = false;
				_UILayer.visible = true;
				_ActiveLayer.visible = true;
				_MapLayer.visible = true;
				break;
			case STAT_LOCK_ALERT:
				unlockLayer(_AlertLayer);
				lockLayer(_PreLoadLayer);
				lockLayer(_MapLoadLayer);
				lockLayer(_UILayer);
				lockLayer(_ActiveLayer);
				lockLayer(_MapLayer);
				_AlertLayer.visible = true;
				_PreLoadLayer.visible = false;
				_MapLoadLayer.visible = false;
				_UILayer.visible = true;
				_ActiveLayer.visible = true;
				_MapLayer.visible = true;
				break;
			}
		}
		
		private static function lockLayer(obj:Sprite):void
		{
			obj.mouseEnabled = false;
			obj.mouseChildren = false;
		}
		
		private static function unlockLayer(obj:Sprite):void
		{
			obj.mouseEnabled = true;
			obj.mouseChildren = true;
		}
		
	}
}